package com.idol.sql.session;

import com.idol.config.XMLConfigBuilder;
import com.idol.pojo.Configeration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className SqlSessionFactory
 * @description
 * @date 2020/9/26 15:19
 **/
public class SqlSessionFactoryBuilder {
    public SqlSessionFactory builder(InputStream inputStream) throws DocumentException, PropertyVetoException {
        // 解析数据库配置信息及 SQL 信息
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configeration configeration = xmlConfigBuilder.parseConfig(inputStream);

        // 创建 SqlSessionFactory 对象，用以生产 SqlSession
        SqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configeration);

        return defaultSqlSessionFactory;
    }
}
